/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

/**
 * <p>Project: app2022 - Ex3
 * <p>Powered by webrx On 2022-02-07 17:15:09
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Ex3 {
    Object a = new Object();
    Object b = new Object();

    public static void main(String[] args) {
        var t = new Ex3();
        new Thread(t::m1, "T1").start();
        new Thread(t::m2, "T2").start();
    }

    void m1() {
        String tn = Thread.currentThread().getName();
        synchronized (a) {
            try {
                Thread.sleep(10);
            } catch (Exception e) {
                e.printStackTrace();
            }
            synchronized (b) {
                System.out.println(tn);
            }
        }
    }

    void m2() {
        String tn = Thread.currentThread().getName();
        synchronized (b) {
            try {
                Thread.sleep(10);
            } catch (Exception e) {
                e.printStackTrace();
            }
            synchronized (a) {
                System.out.println(tn);
            }
        }
    }
}
